package com.offroader.utils;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.util.EncodingUtils;

import com.offroader.core.OffRoaderApp;

public class FileUtils {

	//从assets 文件夹中获取文件并读取数据
	public static String getFromAssets(String fileName) {
		String result = "";
		InputStream in = null;

		try {

			in = OffRoaderApp.getInstance().getResources().getAssets().open(fileName);
			//获取文件的字节数
			int lenght = in.available();
			//创建byte数组
			byte[] buffer = new byte[lenght];
			//将文件中的数据读到byte数组中
			in.read(buffer);
			result = EncodingUtils.getString(buffer, "utf-8");

		} catch (Exception e) {
			LogUtils.error(e.getMessage(), e);
		} finally {
			if (in != null)
				try {
					in.close();
				} catch (IOException e) {
				}
		}

		return result;
	}

}
